#include <dbg.h>
#include <gtest/gtest.h>
using namespace std;

class Solution {
public:
    int maxTurbulenceSize(vector<int>& arr) {
        int n = arr.size();
        if (n < 2) {
            return n;
        }

        int res = 1;

        int up = 1;
        int down = 1;
        for (int i = 1; i < arr.size(); ++i) {
            if (arr[i - 1] < arr[i]) {  // 上升
                up = down + 1;
                down = 1;
            } else if (arr[i - 1] > arr[i]) {  // 下降
                down = up + 1;
                up = 1;
            } else {
                up = down = 1;
            }
            res = max(res, max(up, down));
        }

        return res;
    }
};

TEST(TEST1, maxTurbulenceSize) {
    Solution s;

    vector<int> arr = {9, 4, 2, 10, 7, 8, 8, 1, 9};
    EXPECT_EQ(s.maxTurbulenceSize(arr), 5);
}

TEST(TEST2, maxTurbulenceSize) {
    Solution s;

    vector<int> arr = {4, 8, 12, 16};
    EXPECT_EQ(s.maxTurbulenceSize(arr), 2);
}

TEST(TEST3, maxTurbulenceSize) {
    Solution s;

    vector<int> arr = {100};
    EXPECT_EQ(s.maxTurbulenceSize(arr), 1);
}

int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}